package DataFile;

import java.nio.ByteBuffer;
import java.util.Formatter;

import ClassData.ConstantPoolInteger_Info;

public class Structure_CP_IntegerInfo extends Structure_CP_Constant {

	ConstantPoolInteger_Info myIntegerInfo;
	
	public Structure_CP_IntegerInfo(ConstantPoolInteger_Info myIntegerInfo) {
		this.myIntegerInfo=myIntegerInfo;
	}

	public int getMemorySize() {
		int size;
		
		size =BYTE_WIDTH;	// Type
		size+=INTEGER_WIDTH;	// class name index
		
		return(size);	
	}

	protected String getMemoryMapAsString() {
//		String returnString;
//		
//		returnString=getAdressAsHexString(baseAdress);
//		returnString+=" : (integer info) : size - "+new Formatter().format("%3d",getMemorySize());
//		returnString+=" Value : "+myIntegerInfo.getValue()+"\n";
		Formatter fmt = new Formatter();
		return "" + fmt.format("%s |%14s | size - %3d | %s\n", 
				getAdressAsHexString(baseAdress), 
				"(long info)", 
				getMemorySize(),
				"value - " + myIntegerInfo.getValue());
		//return(returnString);
	}

	/**
	 *  writes data into memory file
	 *  
	 *  @author Tavin
	 *  
	 *  @param fileData buffer for data 
	 */
	
	public void writeData(ByteBuffer fileData) {
		fileData.position(baseAdress-DataFileCreator.BASE_MEMORY_ADRESS);
		fileData.put((byte)myIntegerInfo.getType());
		fileData.putInt(myIntegerInfo.getValue());
	}

}
